package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponDetailVO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-20
 */
@Api(tags = "优惠券管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/coupons")
public class CouponController {
    private final ICouponService couponService;

    /**
     * 新增优惠券
     */
    @PostMapping
    @ApiOperation("新增优惠券")
    public void saveCoupon(@RequestBody CouponFormDTO dto) {
        couponService.saveCoupon(dto);
    }

    /**
     * 分页查询优惠券
     */
    @GetMapping("page")
    @ApiOperation("分页查询优惠券")
    public PageDTO<CouponPageVO> queryCouponByPage(CouponQuery query) {
        return couponService.queryCouponByPage(query);
    }

    /**
     * 发送优惠券接口
     */
    @ApiOperation("发放优惠券接口")
    @PutMapping("/issue")
    public void beginIssue(@RequestBody @Valid CouponIssueFormDTO dto) {
        couponService.beginIssue(dto);
    }
    /**
     * 修改优惠券
     */
    @PutMapping("/{id}")
    @ApiOperation("修改优惠券")
    public void updateCoupon( @RequestBody CouponFormDTO dto) {
        couponService.updateCoupon(dto);
    }
    /**
     * 删除优惠券
     */
    @DeleteMapping("{id}")
    @ApiOperation("删除优惠券")
    public void deleteCoupon(@PathVariable("id") Long id) {
        couponService.removeCouponById(id);
    }
    /**
     * 根据id查询优惠券
     */
    @GetMapping("{id}")
    @ApiOperation("根据id查询优惠券")
    public CouponDetailVO queryCouponById(@PathVariable("id") Long id) {
        return couponService.getCouponById(id);
    }

    /**
     * 暂停发放优惠券
     */
    @PutMapping("{id}/pause")
    @ApiOperation("暂停发放")
    public void pauseIssue(@PathVariable("id") Long id) {
        couponService.pauseIssue(id);
    }
    /**
     * 领取优惠券
     */
    @GetMapping("list")
    @ApiOperation("查询发放中的优惠券")
    public List<CouponVO> quaryCouponList() {
        return couponService.receiveCoupon();
    }

}
